function updatePreco() {
    var ingredientestList = document.getElementsByName("ingredientes");
       
        
    try{
        var precoIngredientes=0;
        
        for(var i=0;i< ingredientestList.length;i++){
            
            if(ingredientestList[i].checked){
                var Split = new Array();
                Split = ingredientestList.item(i).value.split(",");
                precoIngredientes=eval(precoIngredientes +'+'+ Split[0]);
            }
        }
        var precoMassa = document.getElementById("massaSelect").value.split(",")[0];
        
        var precoParcial= eval(precoIngredientes + '+' + precoMassa);
        var precoPizza=eval(priceMultiplier(document.getElementById("tamanho").value)+'*'+precoParcial);
        document.getElementById("precoPizza").innerHTML=  precoPizza+ ' euros';
        document.getElementById("preco").value= precoPizza;
    }catch(err){
        alert(err);
    }
}
function priceMultiplier(price){
                
    var multiplier=0;
    if(price == 'pequena'){
        multiplier=1;
    }
    if(price=="media"){
        multiplier=1.75;
    }
    if(price=="grande"){
        multiplier=2.5;
    }
    return multiplier;
}
function loadXMLDoc(dname,assync)
{
    if (window.XMLHttpRequest)
    {
        xhttp=new XMLHttpRequest();
    }
    else
    {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET",dname,assync);
    xhttp.send("");
    return xhttp.responseXML;
}

function displayConfigurador()
{
    try{
        xml=loadXMLDoc("configurador?action=getXMLfile",false);
        xsl=loadXMLDoc("xml/configurador.xsl",false);
              
        // code for IE
        if (window.ActiveXObject)
        {
            ex=xml.transformNode(xsl);
            document.getElementById("pizzaDiv").innerHTML=ex;
        }
        // code for Mozilla, Firefox, Opera, etc.
        else if (document.implementation && document.implementation.createDocument)
        {
            xsltProcessor=new XSLTProcessor();
            xsltProcessor.importStylesheet(xsl);
            resultDocument = xsltProcessor.transformToFragment(xml,document);
            document.getElementById("pizzaDiv").appendChild(resultDocument);
            
        }
    }catch(err){
        alert(err);
    }
}

function priceMultiplier(price){
    var multiplier=0;
    if(price == 'pequena'){
        multiplier=1;
    }
    if(price=="media"){
        multiplier=1.75;
    }
    if(price=="grande"){
        multiplier=2.5;
    }
    return multiplier;
}
function loadXMLDoc(dname)
{
    if (window.XMLHttpRequest)
    {
        xhttp=new XMLHttpRequest();
    }
    else
    {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET",dname,false);
    xhttp.send("");
    return xhttp.responseXML;
}
